package com.jm.common.conf.mybatis;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.metadata.TableInfo;

import java.util.List;


/**
 * @author kong
 * 配置sql 增强
 */

public class SqlInjectorPlus extends DefaultSqlInjector {
    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
        //继承原来的通用方法
        List<AbstractMethod> methods = super.getMethodList(mapperClass, tableInfo);
        methods.add(new EnhanceBatchInsert("enhanceBatchInsert"));
        methods.add(new EnhanceBatchDelete("enhanceBatchDelete"));
        methods.add(new EnhanceBatchUpdate("enhanceBatchUpdate"));
        methods.add(new EnhanceUpdate("enhanceUpdate"));
        methods.add(new EnhanceDelete("enhanceDelete"));
        return methods;
    }


//    @Override
//    public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
//        Stream.Builder<AbstractMethod> builder = Stream.<AbstractMethod>builder()
//                .add(new Insert())
//                .add(new Delete())
//                .add(new DeleteByMap())
//                .add(new Update())
//                .add(new SelectByMap())
//                .add(new SelectCount())
//                .add(new SelectMaps())
//                .add(new SelectMapsPage())
//                .add(new SelectObjs())
//                .add(new SelectList())
//                .add(new SelectPage())
//                .add(new EnhanceBatchInsert())
//                .add(new EnhanceBatchDelete())
//                .add(new EnhanceBatchUpdate())
//                .add(new EnhanceUpdate())
//                .add(new EnhanceDelete());
//        if (tableInfo.havePK()) {
//            builder.add(new DeleteById())
//                    .add(new DeleteBatchByIds())
//                    .add(new UpdateById())
//                    .add(new SelectById())
//                    .add(new SelectBatchByIds());
//        } else {
//            logger.warn(String.format("%s ,Not found @TableId annotation, Cannot use Mybatis-Plus 'xxById' Method.",
//                    tableInfo.getEntityType()));
//        }
//        return builder.build().collect(toList());
//    }
}
